<?php

declare(strict_types=1);

/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://hyperf.wiki
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */

use Hyperf\HttpServer\Router\Router;
use App\Middleware\Auth\AdminMiddleware;

/* Home Routes */
Router::addRoute(['GET', 'POST', 'HEAD'], '/', [App\Controller\Home\IndexController::class, 'index']);

Router::get('/favicon.ico', function () {
    return '';
});


/* Admin Routes */
Router::addGroup('/admin', function () {
    // 登录请求
    Router::post('/post_login', [App\Controller\Admin\AuthController::class, 'postLogin']);
});

Router::addGroup('/admin', function () {
    // 登录页
    Router::get('/login', [App\Controller\Admin\AuthController::class, 'login']);
    // 注销登录
    Router::post('/logout', [App\Controller\Admin\AuthController::class, 'logout']);
    // 首页
    Router::get('/index', [App\Controller\Admin\IndexController::class, 'index']);
    // 个人中心
    Router::get('/profile', [App\Controller\Admin\AdminController::class, 'profile']);
    //
    Router::get('/init_url', [App\Controller\Admin\IndexController::class, 'initUrl']);
    // 欢迎页
    Router::get('/welcome', [App\Controller\Admin\IndexController::class, 'welcome']);
    // 菜单（权限）管理
    Router::get('/permissions', [App\Controller\Admin\PermissionController::class, 'index']);
    // 权限添加页面
    Router::get('/permission/create', [App\Controller\Admin\PermissionController::class, 'create']);
    // 权限创建
    Router::post('/permission/store', [App\Controller\Admin\PermissionController::class, 'store']);
    // 获取菜单树形结构
    Router::get('/menus', [App\Controller\Admin\PermissionController::class, 'menus']);
    // 权限编辑页面
    Router::get('/permission/edit/{id}', [App\Controller\Admin\PermissionController::class, 'edit']);
    // 权限信息
    Router::get('/permission/{id}', [App\Controller\Admin\PermissionController::class, 'info']);
    // 权限更新
    Router::put('/permission/{id}', [App\Controller\Admin\PermissionController::class, 'update']);
    // 权限删除
    Router::delete('/permission/{id}', [App\Controller\Admin\PermissionController::class, 'del']);
    // 清空缓存
    Router::post('/clear', [App\Controller\Admin\IndexController::class, 'clear']);
    // 密码页
    Router::get('/password', [App\Controller\Admin\AdminController::class, 'pagePassword']);
    // 修改密码
    Router::post('/password_change', [App\Controller\Admin\AdminController::class, 'passwordChange']);
    // 管理员信息页
    Router::get('/admin/{id}', [App\Controller\Admin\AdminController::class, 'info']);
    // 管理员账号创建
    Router::post('/admin/store', [\App\Controller\Admin\AdminController::class, 'store']);
    // 管理员账号修改
    Router::put('/admin/{id}', [\App\Controller\Admin\AdminController::class, 'update']);
    // 管理员账号删除
    Router::delete('/admin/{id}', [\App\Controller\Admin\AdminController::class, 'del']);

}, ['middleware' => [AdminMiddleware::class]]);
